package com.cx.Controller;


import com.cx.entity.Article;
import com.cx.service.impl.ArticleServiceImpl;
import com.cx.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author cx
 * @since 2024-06-07
 */
@CrossOrigin    //解决跨域问题注解
@RestController
@RequestMapping("/")
public class ArticleController {
    //配置基于权重的轮询算法
    @Autowired
    private ArticleServiceImpl articleService;


    //    查询全部文章列表信息
    @RequestMapping("article/list")
    public R getArticleServiceList() {
        return R.ok().put("data", articleService.list());
    }


    //    查询ID文章内容信息
    @RequestMapping("ArticleContent/{id}")    //    地址栏后面直接写id，不需要“？id=1”
    public R getArticleServiceList(@PathVariable("id") Integer id) {
//        增加点击量
        Article article = new Article();
        article.setId(id);
        article.setHits(articleService.getById(id).getHits() + 1);
        articleService.updateById(article);
        return R.ok().put("data", articleService.getById(id));
    }
}